#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int fact(int n)
{
	double result = 0.0;
	if (n > 1 && n <= 9) {
		result = n;
	}
	else if (n > 9 && n <= 189) {
		result = (n - 9) / 2.0 + 9;
		if ((result - (int)result) > 0) {
			result = -1;
		}
	}
	else if (n > 189 && n <= 1000) {
		result = (n - 189) / 3.0 + 99;
		if ((result - (int)result) > 0) {
			result = -1;
		}
	}
	return result;
}

int main()
{
	int i, t, a;
	double r;
	scanf("%d", &t);
	for (i = 0; i < t; i++) {
		scanf("%d", &a);
		r = fact(a);
		printf("%.0lf\n", r);
	}


	return 0;
}//1057